#include<iostream>
using namespace std;
int main() {
	int n, MIN=999999999 , MAX = 0, arr[10];
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		if (MAX < arr[i]) {
			MAX = arr[i];
		}
		if (MIN > arr[i]) {
			MIN = arr[i];
		}
	}

	int h = 0;
	while (MIN != arr[h]) {
		h++;
	}
	arr[h] = arr[0];
	arr[0] = MIN;


	int k = 0;
	while (MAX != arr[k]) {
		k++;
	}
	arr[k] = arr[n - 1];
	arr[n - 1] = MAX;

	for (int a = 0; a < n ; a++) {
		cout << arr[a] << " ";
	}
	return 0;
}